import allure
from appium.webdriver.common.appiumby import AppiumBy


from tests.app.pages.member_page import MemberPage
from tests.app.pages.quick_add_members_page import QuickAddMembersPage
from tests.app.pages.wecom import Wecom

@allure.feature("通讯录页面")
class AddressBookPage(Wecom):
    __ADD_BUTTON=(AppiumBy.XPATH,"//*[@text='添加成员']")
    __MANUALLY_ADD=(AppiumBy.XPATH,"//*[@text='手动输入添加']")
    __FRIST_NAME=(AppiumBy.XPATH,"//*[@text='卡莎']")
    __SECOND_NAME=(AppiumBy.XPATH,"//*[@text='薇恩']")
    __THIRD_NAME=(AppiumBy.XPATH,"//*[@text='霞']")

    @allure.story("跳转添加成员页面")
    def goto_add_members_page(self):
        with allure.step("点击添加成员"):
            self.swip_find(by=AppiumBy.XPATH,value="//*[@text='添加成员']")
            self.find_and_click(*self.__ADD_BUTTON)
        with allure.step("点击手动输入添加"):
            self.find_and_click(*self.__MANUALLY_ADD)
        return QuickAddMembersPage(self.driver)

    def get_member(self, member_name):
        ele= self.find(AppiumBy.XPATH, value=f'//*[@text = "{member_name}"]')
        return ele.text

    def goto_member_page(self,member_name):
        self.find_and_click(AppiumBy.XPATH, value = f'//*[@text = "{member_name}"]')
        return MemberPage(self.driver)